Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider an array of elements arr[5]= {5,4,3,... Start Learning for Free
Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array.  
  • a)
    4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5
  • b)
    5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5
  • c)
    4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2
  • d)
    4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps...
In the insertion sort , just imagine that the first element is already sorted and all the right side Elements are unsorted, we need to insert all elements one by one from left to right in the sorted Array. Sorted : 5
unsorted : 4 3 2 1 Insert all elements less than 5 on the left (Considering 5 as the key ) Now key value is 4 and array will look like this Sorted : 45 unsorted : 3 2 1 Similarly for all the cases the key will always be the newly inserted value and all the values will be compared to that key and inserted in to proper position
View all questions of this test
Most Upvoted Answer
Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps...
Insertion Sort Steps for Array Arr[5] = {5, 4, 3, 2, 1}

Step 1: Compare the first two elements, i.e., 5 and 4. As 4 is smaller, swap them.
Arr[5] = {4, 5, 3, 2, 1}

Step 2: Compare the second and third elements, i.e., 5 and 3. As 3 is smaller, swap them.
Arr[5] = {4, 3, 5, 2, 1}

Step 3: Compare the third and fourth elements, i.e., 5 and 2. As 2 is smaller, swap them.
Arr[5] = {4, 3, 2, 5, 1}

Step 4: Compare the fourth and fifth elements, i.e., 5 and 1. As 1 is smaller, swap them.
Arr[5] = {4, 3, 2, 1, 5}

Step 5: Now, the first element is sorted. Compare the second and third elements, i.e., 3 and 2. As 2 is smaller, swap them.
Arr[5] = {4, 2, 3, 1, 5}

Step 6: Compare the first and second elements, i.e., 4 and 2. As 2 is smaller, swap them.
Arr[5] = {2, 4, 3, 1, 5}

Step 7: Compare the third and fourth elements, i.e., 3 and 1. As 1 is smaller, swap them.
Arr[5] = {2, 4, 1, 3, 5}

Step 8: Compare the second and third elements, i.e., 4 and 1. As 1 is smaller, swap them.
Arr[5] = {2, 1, 4, 3, 5}

Step 9: Compare the first and second elements, i.e., 2 and 1. As 1 is smaller, swap them.
Arr[5] = {1, 2, 4, 3, 5}

Step 10: Now, the first two elements are sorted. Compare the third and fourth elements, i.e., 4 and 3. As 3 is smaller, swap them.
Arr[5] = {1, 2, 3, 4, 5}

Step 11: Now, the first three elements are sorted. Compare the fourth and fifth elements, i.e., 4 and 5. As they are already in sorted order, no swapping is required.
Arr[5] = {1, 2, 3, 4, 5}

Final Arrangement: The final sorted array is {1, 2, 3, 4, 5}.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer?
Question Description
Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer?.
Solutions for Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer?, a detailed solution for Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. a)4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5b)5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5c)4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2d)4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev